package za.co.felixsol.sf.gcode.instructions;

import java.util.Comparator;

public class InstructionParameter {

	String name;
	Integer sequence;
	Object value;

	public InstructionParameter(String name, Object value) {
		super();
		this.name = name;
		this.value = value;
		sequence = 0;
	}

	public InstructionParameter(String name, Integer sequence, Object value) {
		super();
		this.name = name;
		this.sequence = sequence;
		this.value = value;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Object getValue() {
		return value;
	}

	public void setValue(Object value) {
		this.value = value;
	}

	public Integer getSequence() {
		return sequence;
	}

	public void setSequence(Integer sequence) {
		this.sequence = sequence;
	}
	
	public static class InstructionParameterComparator implements  Comparator {

		@Override
		public int compare(Object o1, Object o2) {
			if ((o1 == null) && (o2 == null)) return 0;
			if ((o1 == null) && (o2 != null)) return -1;
			if ((o1 != null) && (o2 == null)) return 1;
			InstructionParameter p1 = (InstructionParameter)o1;
			InstructionParameter p2 = (InstructionParameter)o2;
			if (p1.getSequence().compareTo(p2.getSequence()) == 0) {
				return p1.getName().compareTo(p2.getName());
			} else {
				return p1.getSequence().compareTo(p2.getSequence());
			}
		}
		
		
		
	}

}
